package com.sfzy.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.sfzy.entity.Question;
import com.sfzy.mapper.QuestionMapper;
import com.sfzy.service.QuestionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class QuestionServiceImpl implements QuestionService {
    @Autowired
    private QuestionMapper questionMapper;
    @Override
    public int addQuestion(Question question) {
        return questionMapper.addQuestion(question);
    }

    @Override
    public int deleteQuestion(int id) {
        return questionMapper.deleteQuestion(id);
    }

    @Override
    public int updateQuestion(Question question) {
        return questionMapper.updateQuestion(question);
    }

    @Override
    public Question getQuestionById(int id) {
        return questionMapper.getQuestionById(id);
    }

    @Override
    public PageInfo<Question> getQuestions(Question question, int pageNum, int pageSize) {
        PageHelper.startPage(pageNum,pageSize);
        List<Question> questions = questionMapper.getQuestions(question);
        PageInfo<Question> pageInfo = new PageInfo<>(questions);
        return pageInfo;
    }
}
